/* ================================================================
*   Copyright (C) 2020 All rights reserved.
*
*   文件名称：rewrite_remove_example.cpp
*   创 建 者：xunmenglong
*   创建日期：2020年12月06日
*   描    述：
*
================================================================ */


#ifndef REWRITE_REMOVE_EXAMPLE_CPP
#define REWRITE_REMOVE_EXAMPLE_CPP

#include "xkvstore.h"

int main(int argc, char ** argv) {
    xkvstore kv;
    int ret = kv.init("./data");
    if (ret != 0) {
        LOG(ERROR) << "xkvstore init fail";
        return -1;
    }
    int rewrite_key = 11111;
    string rewrite_value = "hello xkvstore";
    ret = kv.set(rewrite_key, rewrite_value.c_str(), rewrite_value.size()+1);
    if (ret != 0) {
        LOG(ERROR) << "rewrite key fail: " << rewrite_key;
        return -1;
    }
    LOG(NOTICE) << "rewrite key succ: " << rewrite_key;

    int remove_key = 10001;
    ret = kv.remove(remove_key);
    if (ret == 1) {
        LOG(NOTICE) << "remove key not exists: " << remove_key;
        return 0;
    } else if (ret < 0) {
        LOG(ERROR) << "remove key fail: " << remove_key;
        return -1;
    }

    LOG(NOTICE) << "remove key [" << remove_key << "] succ, try to run `./read_example`";

    return 0;
}

#endif
